<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>编辑学习品质项</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="infoForm" label-width="90px" ref="editForm">
          <el-form-item label="品质名称：" prop="num">
            <el-input v-model="infoForm.name" placeholder="填写餐品名称" size="small"></el-input>
          </el-form-item>
          <el-form-item label="品质评分：" prop="num">
            <el-button @click.native="addPoint()" size="small">添加评分项</el-button>
            <el-table
                ref="multipleTable"
                :data="arryList"
                tooltip-effect="dark"
                style="width: 100%"
                border>
              <el-table-column
                  label="评分名称">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.name" placeholder="评分名称" size="small"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                  label="副标题">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.small_name" placeholder="副标题" size="small"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                  prop="name"
                  label="评分分值">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.score" placeholder="评分分值" size="small"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                  label="评分备注">
                <template slot-scope="scope">
                  <el-input
                      type="textarea"
                      :autosize="{ minRows: 2, maxRows: 4}"
                      placeholder="评分备注"
                      v-model="scope.row.remark">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column
                  label="操作"
                  width="80">
                <template slot-scope="scope">
                  <el-button type="danger" size="small" plain @click="detelFn(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item label="品质描述：" prop="num">
            <el-input v-model="infoForm.remark" placeholder="填写品质描述" size="small"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {qualityDetail, qualityEdit, qualityAdd} from '@/api/admin/acquisition'

export default {
  props: ['visible', 'foodOption'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      arryList: [],
      dialogVisible: false,
      infoForm: {
        name: '',
        fraction: '',
        remark: ''
      },
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible && this.foodOption) {
        this.getDetail()
      }
      if (!this.visible) {
        this.infoForm.name = ''
        this.arryList = []
      }
    }
  },
  created() {

  },
  methods: {
    addPoint() {
      this.arryList.push({
        name: '',
        small_name: '',
        score: '',
        remark: '',
      })
    },
    detelFn(index) {
      this.arryList.splice(index, 1)
    },
    checkEditFn() {
      console.log('jjj:', this.arryList, this.infoForm)
      if (!this.infoForm.name) {
        this.$message.error('请填写品质名称');
        return
      }
      if (!this.arryList.length) {
        this.$message.error('请填写评分项');
        return
      }
      let data_ = JSON.parse(JSON.stringify(this.infoForm))
      data_.fraction = JSON.stringify(this.arryList)
      if (!this.foodOption) {
        qualityAdd(data_).then(res => {
          console.log(res)
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('initPage')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        data_.id = this.foodOption.id
        qualityEdit(data_).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('initPage')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    getDetail() {
      qualityDetail({id: this.foodOption.id}).then(res => {
        this.infoForm.name = res.vo.name
        this.infoForm.remark = res.vo.remark
        this.arryList = JSON.parse(res.vo.fraction)
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 800px;
  height: 600px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


